
import { commonConstants } from 'hhlt-core/constants'
import { systemUtils} from 'hhlt-core/utils'
import { formatUtils,requestUtils} from 'hhlt-vue/utils'
import { IPageInfo} from 'hhlt-core/src/model/page/pageInfo'
import { IDataTablePager} from 'hhlt-core/src/model/page/dataTablePager'
import { VxeGridPropTypes, VxeTableDefines } from 'vxe-table'
import { IColumnInfo} from 'hhlt-core/src/model/form/column'
import { IExecuteData, IExecuteList} from 'hhlt-core/src/model/base/resultModel'
import { FormRules } from 'element-plus'
import { fixedDatasource} from "hhlt-core/constants"
import { objectUtils } from 'hhlt-core/utils'
import { requestContextPath } from 'lxsh-cer-web-pc/src/constants'
import { ICerOfficeImpro, ICerOfficeImproQO, ICerOfficeImproVO,CerOfficeImpro } from 'lxsh-cer-web-pc/src/model/cer/cer/office-impro/cer-office-impro'
import { IBaseComboVO } from 'hhlt-core/src/model/base/baseDto'
/**
* 办公室减碳业务实现
*/
export default {
//获取页面信息，根据不同的功能编码来加载不同的页面
getPageInfo:function(pageInfo:IPageInfo<ICerOfficeImpro>){
  this.getColumnInfo()
},
/**
* 获取列信息
*/
getColumnInfo(successCallback?:(columnsParam:VxeGridPropTypes.Columns)=>void){
    var columns:VxeGridPropTypes.Columns = [
      { type: 'checkbox', width: 50 },
      { type: 'seq', width: 60,align:'center',title:'序号' },
      { field: 'id', title: '主键ID', visible:false },
      { field: 'officeName', title: '办公室', showOverflow: true, sortable: true,width:'100px' },
      { field: 'week', title: '周次', showOverflow: true, sortable: true,width:'100px' },
      { field: 'stratTime', title: '开始时间', formatter: formatUtils.formatDate, showOverflow: true, sortable: true ,width:'160px'},
      { field: 'endTime', title: '结束时间', formatter: formatUtils.formatDate, showOverflow: true, sortable: true ,width:'160px'},
      { field: 'lightTime', title: '开灯时长', showOverflow: true, sortable: true,width:'100px' },
      { field: 'airTime', title: '空调时长', showOverflow: true, sortable: true,width:'100px' },
      { field: 'reduceCount', title: '减碳量', showOverflow: true, editRender: {}, slots: { edit: 'reduceCount' },sortable: true,width:'120px' },
      { field: 'addUserName', title: '添加者名', showOverflow: true, sortable: true,width:'100px' },
      { field: 'addDate', title: '添加时间', formatter: formatUtils.formatDateDefault, showOverflow: true, sortable: true ,width:'160px'},
      { title: '操作', width: 200, slots: { default: 'operate' },fixed:'right' }
    ];
    if(successCallback){
      successCallback(columns);
    }
  },
  /**
   * 获取检索条件
   */
  getSearchCondition(successCallback:(searchCondtionParam:IColumnInfo[],queryParams:ICerOfficeImproQO) => void){
    var searchCondition = [
      { columnCode: 'officeName', columnName: '办公室', basicControlType:commonConstants.enumBasicControlType.COMBOBOX,defaultValue:"",controlAttrValue:requestContextPath.cer + '/cer/officeData/getComboList',controlNeedValue:'' },
      { columnCode: 'week', columnName: '周次', basicControlType:commonConstants.enumBasicControlType.TEXT_BOX,defaultValue:"",controlAttrValue:"" },
      { columnCode: 'stratTime', columnName: '开始时间', basicControlType:commonConstants.enumBasicControlType.DATE,defaultValue:"",controlAttrValue:"" },
    ];
    var queryParam:ICerOfficeImproQO = {
        id:undefined,
       /**
	    * officeName:办公室
	    */
    officeName:"",
       /**
	    * week:周次
	    */
    week:undefined,
       /**
	    * stratTime:开始时间
	    */
    stratTime: undefined,
    }
    return successCallback(searchCondition,queryParam);
  },
  /**
   * 单条删除操作
   */
  doDeleteSingle(selectItem:ICerOfficeImproVO,successCallback?:(deleteResult:IExecuteData<string>)=>void):Promise<IExecuteData<string>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/officeImpro/deleteByLogicBatch';
    let list = new Array();
    let item:ICerOfficeImproQO = {
      id:selectItem.id
    }
    list.push(item)
    return requestUtils.delete(url, list,successCallback);
  },
  /**
   * 单条删除操作
   */
  doDeleteBatch(selectList:ICerOfficeImproVO[],successCallback?:(deleteResult:IExecuteData<string>)=>void):Promise<IExecuteData<string>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/officeImpro/deleteByLogicBatch';
    let list = new Array();
    for (let selectItem of selectList) {
      let item :ICerOfficeImproVO = {
        id:selectItem.id
      };
      list.push(item);
    }
    return requestUtils.delete(url, list,successCallback);
  },
  /**
   * 获取分页数据
   */
  getListByPager(queryParam:ICerOfficeImproQO,pager:IDataTablePager<ICerOfficeImproVO>,successCallback?:(queryResult:IExecuteData<IDataTablePager<ICerOfficeImproVO>>) => void):Promise<IExecuteData<IDataTablePager<ICerOfficeImproVO>>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/officeImpro/getListByPager';
    return  requestUtils.getListByPager(url, queryParam, pager,successCallback)
  },
  addForm(formData:ICerOfficeImpro,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/officeImpro/insert";
    return requestUtils.insert(url, formData,successCallback);
  },
  updateForm(formData:ICerOfficeImpro,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/officeImpro/update";
    return requestUtils.update(url, formData,successCallback);
  },
  updateEnable(formData:ICerOfficeImpro,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/officeImpro/updateEnable";
    return requestUtils.update(url, formData,successCallback);
  },
  getInfoByCondition(param:ICerOfficeImproQO,successCallback?:(result:IExecuteData<ICerOfficeImproVO>) => void):Promise<IExecuteData<ICerOfficeImproVO>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/officeImpro/getInfoByCondition";
    return requestUtils.getInfoByCondition(url, param,successCallback);
  },
  exportExcel(param:any,fileName:string,successCallback?:(result:IExecuteData<String>) => void):Promise<IExecuteData<String>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/officeImpro/exportExcel";
    const result:any = requestUtils.exportExcel(url, param,fileName,successCallback);
    if(result.success){
      if(successCallback){
        successCallback(result)
      }
    }
    return result;
  },
  //获取表单项
  getFormDataItem(successCallback:(formData:ICerOfficeImpro,verify:FormRules) => void){
    var formData:ICerOfficeImpro = new CerOfficeImpro()
        // 校验
    var verify:FormRules = {
        officeName: [{
            required: true,
            message: "办公室不能为空！"
        }],
        week: [{
            required: true,
            message: "周次不能为空！"
        }],
        stratTime: [{
            required: true,
            message: "开始时间不能为空！"
        }],
        endTime: [{
            required: true,
            message: "结束时间不能为空！"
        }],
        lightTime: [{
            required: true,
            message: "开灯时长不能为空！"
        }],
        airTime: [{
            required: true,
            message: "空调时长不能为空！"
        }],
    }
    return successCallback(formData,verify)
  },

  //获取系数
  getTypeGroupComboByGroup(successCallback?:(result:IExecuteList<IBaseComboVO>) => void):Promise<IExecuteList<IBaseComboVO>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") +'/cer/typeGroup/getTypeGroupComboByGroup/办公';
    let param ={
      id:undefined
    };
    return requestUtils.getListByCondition(url, param,successCallback);
  },

}
